let express = require('express');
let mysql = require('mysql');
let router = express.Router();
const multer = require('multer')
const formidable = require('formidable')
let connection = mysql.createConnection({
    host : 'localhost',
    user:'root',
    password : 'root',
    database : 'express'
});
// const upload = multer({
//     dest : '../upload/'
// });
router.post('/submitForm',multer({
    dest : '../public/images'
}).array('images', 1), function(req, res){
    let form = new formidable.IncomingForm();
    form.parse(req, function(err, fields, files){
        if (err) return res.redirect(303,'/error');
        console.log('received fields');
        console.log(fields);
        console.log(files);
    });
    res.json({
        status : 200
    });
});
module.exports = router;
